use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(GitlabInfo::Table)
                    .if_not_exists()
                    .col(pk_auto(GitlabInfo::Id))
                    .col(string_len_null(GitlabInfo::Host, 32))
                    .col(string_len_null(GitlabInfo::Token, 64))
                    .col(string_len_null(GitlabInfo::UserId, 255))
                    .col(string_len_null(GitlabInfo::UserName, 255))
                    .col(string_len_null(GitlabInfo::UserEmail, 255))
                    .col(boolean_null(GitlabInfo::Https))
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(GitlabInfo::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum GitlabInfo {
    Table,
    Id,
    Host,
    Token,
    UserId,
    UserName,
    UserEmail,
    Https,
}
